package drawing; /**
 * Copyright 2011 Jonathan Haas
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import parts.main.Inverter;
import parts.main.Led;
import parts.model.Part;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.util.ArrayList;

public class CadPane extends Component {

    private ArrayList<Part> _parts = new ArrayList<Part>();

    public int getZoomFactor() {
        return _zoomFactor;
    }

    private int _zoomFactor = 8;

    public CadPane() {
        _parts.add(new Inverter(8, 6));
        _parts.add(new Led(8, 8));
    }

    @Override
    public void paint(final Graphics g) {
        final Graphics2D g2d = (Graphics2D) g;
        g2d.scale(_zoomFactor, _zoomFactor);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setStroke(new BasicStroke(1f / _zoomFactor));
        for (Part part : _parts) {
            final AffineTransform transform = g2d.getTransform();
            g2d.translate(part.getX(), part.getY());
            part.getView().draw(g2d, this.getZoomFactor());
            g2d.setTransform(transform);
        }
    }
}
